package com.cheung.leetcode.hash;

import org.junit.jupiter.api.Test;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.hash
 * @Author :  cheungming
 * @CreateTime : 2024-05-02 10:55:56
 * @Description : 383题
 * @Version : 1.0
 */
public class Code383Test {


    public boolean canConstruct(String ransomNote, String magazine) {
        int[] array = new int[26];
        for (int i = 0; i < magazine.length(); i++) {
            array[magazine.charAt(i) - 'a']++;
        }

        for (int i = 0; i < ransomNote.length(); i++) {
            array[ransomNote.charAt(i) - 'a']--;
        }

        for (int i : array) {
            if (i < 0) {
                return false;
            }
        }

        return true;
    }


    @Test
    public void test1() {
        String ransomNote = "a", magazine = "b";
        assert !canConstruct(ransomNote, magazine);
    }

    @Test
    public void test2() {
        String ransomNote = "aa", magazine = "ab";
        assert !canConstruct(ransomNote, magazine);
    }

    @Test
    public void test3() {
        String ransomNote = "aa", magazine = "aab";
        assert canConstruct(ransomNote, magazine);
    }
}
